<?php
namespace app\admin\controller;
use think\View;

class Seoset extends Auth
{
    public function __construct()
    {
        parent::__construct();
        $this->isLogin();
        $this->seoset = M('Seoset');
        $active['seo']['seoset']=1;
        $this->assign('active', $active);
    }
    public function index()
    {
        $this->view->seoset = $this->seoset->where(['id'=>1])->find();
        return $this->view->fetch();
    }
    public function doseo()
    {
        if(IS_POST){
            $data['hometitle'] = $_POST['hometitle'];
            $data['title_type'] = $_POST['title_type'];
            $data['keywords'] = $_POST['keywords'];
            $data['altname'] = $_POST['altname'];
            $data['atitle'] = $_POST['atitle'];
            $data['linkname'] = $_POST['linkname'];
            $data['content'] = $_POST['content'];
            $data['seocontent'] = $_POST['seocontent'];
            $data['created_at'] = time();
            $data['updated_at'] = time();

            $seo =  $this->seoset->where(['id'=>1])->find();
            if(isset($seo)){
                $this->seoset->where(['id'=>1])->save($data);
            }else{
                $this->seoset->add($data);
            }
            return $this->success('设置成功', U('Seoset/index'));
        }
    }
}
